<script type="text/javascript">
    $(document).ready(function(){
        $('#no_induk').blur(function() {
            $("#nama").css("color", "black");
            $("#nama").text("");
            $("#kelas").text("");
            $("#kelamin").text("");
            $("#usia").text("");
            $("#siswa_id").val("");
            $("#submit").attr('disabled','disabled');
            if($('#no_induk').val()!=""){
                $.ajax({
                    type : 'POST',
                    url : '<?php echo url_for('pelanggaran/jsonsiswa') ?>',
                    dataType : 'json',
                    data: {
                        no_induk : $('#no_induk').val()
                    },
                    success : function(data){
                        if(data.success){
                            $("#submit").removeAttr("disabled");
                            $("#nama").text(data.nama);
                            $("#kelas").text();
                            $("#kelamin").text(data.jk);
                            $("#usia").text(data.usia+" tahun");
                            $("#siswa_id").val(data.id);
                        }else{
                            $("#nama").text('Siswa dengan No. Induk '+$('#no_induk').val()+' tidak ditemukan!');
                            $("#nama").css("color", "red");
                        }
                    }
                });
            }
        });
    });
</script>
<h1>Form Pelanggaran Siswa</h1>
<form action="<?php echo url_for('pelanggaran/create') ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
    <?php echo $form->renderHiddenFields(false) ?>
    <table class="form">
        <tfoot>
            <tr>
                <td>&nbsp;</td>
                <td>
                    <input type="submit" value="Simpan" id="submit" disabled="disabled" class="button" />
                    &nbsp;<a href="<?php echo url_for('pelanggaran/index') ?>">Back to list</a>
                </td>
            </tr>
        </tfoot>
        <tbody>
            <?php echo $form->renderGlobalErrors() ?>
            <tr>
                <th><?php echo $form['no_induk']->renderLabel() ?></th>
                <td><?php echo $form['no_induk']->render(array('autofocus' => 'autofocus')) ?></td>
            </tr>
            <?php if ($form['no_induk']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['no_induk']->renderError() ?></td>
                </tr>
            <?php endif; ?>
            <tr>
                <th>&nbsp;</th>
                <td>
                    <table style="border: 1px solid #dcdcdc;width: 100%">
                        <tr>
                            <td width="70%" style="font-size: 10pt">Nama</td><td style="font-size: 10pt">Kelas</td></td><td width="1px">&nbsp;</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold;border-bottom: 1px solid #dcdcdc"><span id="nama">&nbsp;</span></td><td style="font-weight: bold;border-bottom: 1px solid #dcdcdc"><span id="kelas">&nbsp;</span></td><td width="1px">&nbsp;</td>
                        </tr>
                        <tr>
                            <td style="font-size: 10pt">Jenis Kelamin</td><td style="font-size: 10pt">Usia</td></td><td width="1px">&nbsp;</td>
                        </tr>
                        <tr>
                            <td style="font-weight: bold"><span id="kelamin">&nbsp;</span></td><td style="font-weight: bold"><span id="usia">&nbsp;</span></td></td><td width="1px">&nbsp;</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <th><?php echo $form['karyawan_id']->renderLabel() ?></th>
                <td><?php echo $form['karyawan_id']->render() ?></td>
            </tr>
            <?php if ($form['karyawan_id']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['karyawan_id']->renderError() ?></td>
                </tr>
            <?php endif; ?>
            <tr>
                <th><?php echo $form['jenis_pelanggaran_id']->renderLabel() ?></th>
                <td><?php echo $form['jenis_pelanggaran_id']->render() ?></td>
            </tr>
            <?php if ($form['jenis_pelanggaran_id']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['jenis_pelanggaran_id']->renderError() ?></td>
                </tr>
            <?php endif; ?>
            <tr>
                <th><?php echo $form['semester_id']->renderLabel() ?></th>
                <td><?php echo $form['semester_id']->render() ?></td>
            </tr>
            <?php if ($form['semester_id']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['semester_id']->renderError() ?></td>
                </tr>
            <?php endif; ?>
            <tr>
                <th><?php echo $form['waktu']->renderLabel() ?></th>
                <td><?php echo $form['waktu']->render(array('id' => 'datetime')) ?></td>
            </tr>
            <?php if ($form['waktu']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['waktu']->renderError() ?></td>
                </tr>
            <?php endif; ?>
            <tr>
                <th><?php echo $form['pembinaan']->renderLabel() ?></th>
                <td><?php echo $form['pembinaan']->render() ?></td>
            </tr>
            <?php if ($form['pembinaan']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['pembinaan']->renderError() ?></td>
                </tr>
            <?php endif; ?>
            <tr>
                <th><?php echo $form['keterangan']->renderLabel() ?></th>
                <td><?php echo $form['keterangan']->render() ?></td>
            </tr>
            <?php if ($form['keterangan']->hasError()): ?>
                <tr>
                    <th>&nbsp;</th>
                    <td><?php echo $form['keterangan']->renderError() ?></td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
</form>
